<?php
 /**
 * 微商城搜索页
 */
define('IN_ECS', true);
define('ECS_ADMIN', true);

require(dirname(__FILE__) . '/includes/init.php');

$keyword = trim($_GET['keyword']);
$smarty->assign('keyword',$keyword);
$vedio_list = search_veido($keyword);

$num = count($vedio_list);
if ($num > 0)
{
	$page_num = '6';
	$page = !empty($_GET['page']) ? intval($_GET['page']) : 1;
	$pages = ceil($num / $page_num);
	if ($page <= 0)
	{
		$page = 1;
	}
	if ($pages == 0)
	{
		$pages = 1;
	}
	if ($page > $pages)
	{
		$page = $pages;
	}
	
	$i = 1;
    foreach ($vedio_list as $vedio_data)
    {
      if (($i > ($page_num * ($page - 1 ))) && ($i <= ($page_num * $page)))
      {
        

       $data[]= $vedio_data;

      }
      $i++;
    }
			
	$pagebar = get_wap_pager($num, $page_num, $page, 'wx_search.php?keyword='.$keyword.'&sort='.(empty($get_sort)?0:$get_sort).'&order='.(empty($get_order)?0:$get_order), 'page');
	
	$smarty->assign('pagebar', $pagebar);
}

  $smarty->assign('vedio_list',$data);  //分完页的数据

  $smarty->display('wx_search.dwt');



/* 搜索视频 */
function search_veido($keyword){
     $sql="select * from {$GLOBALS['ecs']->table('course_vedio')} where title like '%$keyword%'";
     $arr=array();
     $arr=$GLOBALS['db']->getAll($sql);
     foreach($arr as $k=>$v){

     	  $arr[$k]['description']=sub_str($v['description'],12,true);
     }
     return $arr;

}




